package com.pgybook.db.entity.mapper;

import org.springframework.stereotype.Repository;
import com.pgybook.db.entity.domain.FreePeriod;
import com.pgybook.db.entity.domain.FreePeriodEx;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

@Repository
public interface FreePeriodMapper {
    int countByExample(FreePeriodEx example);

    int deleteByExample(FreePeriodEx example);

    @Delete({
            "delete from freeperiod",
            "where FREEPERIODID = #{freeperiodid,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long freeperiodid);

    @Insert({
            "insert into freeperiod (TITLE, STARTTIME, ",
            "ENDTIME, PROCESSEDORDERNUM, ",
            "LATESTORDERID, PROCESSEDBOOKNUM, ",
            "LASTESTBOOKINORDERID, UPDATETIME)",
            "values (#{title,jdbcType=VARCHAR}, #{starttime,jdbcType=TIMESTAMP}, ",
            "#{endtime,jdbcType=TIMESTAMP}, #{processedordernum,jdbcType=INTEGER}, ",
            "#{latestorderid,jdbcType=BIGINT}, #{processedbooknum,jdbcType=BIGINT}, ",
            "#{lastestbookinorderid,jdbcType=BIGINT}, #{updatetime,jdbcType=DATE})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "freeperiodid", before = false, resultType = Long.class)
    int insert(FreePeriod record);

    int insertSelective(FreePeriod record);

    List<FreePeriod> selectByExample(FreePeriodEx example);

    @Select({
            "select",
            "FREEPERIODID, TITLE, STARTTIME, ENDTIME, PROCESSEDORDERNUM, LATESTORDERID, PROCESSEDBOOKNUM, ",
            "LASTESTBOOKINORDERID, UPDATETIME",
            "from freeperiod",
            "where FREEPERIODID = #{freeperiodid,jdbcType=BIGINT}"
    })
    @ResultMap("BaseResultMap")
    FreePeriod selectByPrimaryKey(Long freeperiodid);

    int updateByExampleSelective(@Param("record") FreePeriod record, @Param("example") FreePeriodEx example);

    int updateByExample(@Param("record") FreePeriod record, @Param("example") FreePeriodEx example);

    int updateByPrimaryKeySelective(FreePeriod record);

    @Update({
            "update freeperiod",
            "set TITLE = #{title,jdbcType=VARCHAR},",
            "STARTTIME = #{starttime,jdbcType=TIMESTAMP},",
            "ENDTIME = #{endtime,jdbcType=TIMESTAMP},",
            "PROCESSEDORDERNUM = #{processedordernum,jdbcType=INTEGER},",
            "LATESTORDERID = #{latestorderid,jdbcType=BIGINT},",
            "PROCESSEDBOOKNUM = #{processedbooknum,jdbcType=BIGINT},",
            "LASTESTBOOKINORDERID = #{lastestbookinorderid,jdbcType=BIGINT},",
            "UPDATETIME = #{updatetime,jdbcType=DATE}",
            "where FREEPERIODID = #{freeperiodid,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(FreePeriod record);
}
